import request from '@/utils/request'
// import qs from 'qs'

// 认证服务器

// 删除信息
export function delServer (params) {
  var data = fromData(params)
  return request({
    url: '/server/del_info',
    method: 'post',
    data
  })
}

// 增加Ldap认证服务器
export function addLdapInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/addLdapInfo',
    method: 'post',
    data
  })
}

// 增加Radius认证服务器
export function addRadiusInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/addRadiusInfo',
    method: 'post',
    data
  })
}

// 增加本地认证服务器
export function addLocalInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/addLocalInfo',
    method: 'post',
    data
  })
}

// 查询Ldap认证服务器所有用户dn
export function searchUdnInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/searchUdnInfo',
    method: 'post',
    data
  })
}

// 编辑Ldap认证服务器
export function editLdapInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/editLdapInfo',
    method: 'post',
    data
  })
}

// 编辑Radius认证服务器
export function editRadiusInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/editRadiusInfo',
    method: 'post',
    data
  })
}

// 编辑本地认证服务器
export function editLocalInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/editLocalInfo',
    method: 'post',
    data
  })
}

// 获取Ldap认证服务器
export function getLdapInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/getLdapInfo',
    method: 'post',
    data
  })
}

// 获取Radius认证服务器
export function getRadiusInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/getRadiusInfo',
    method: 'post',
    data
  })
}

// 获取列表
export function getServerArray (params) {
  var data = fromData(params)
  return request({
    url: '/server/getArray',
    method: 'post',
    data
  })
}

// 获取本地认证服务器
export function getLocalInfo (params) {
  var data = fromData(params)
  return request({
    url: '/server/getLocalInfo',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
